package hellfire.system.graphics;

import java.util.Vector;

import android.util.Log;

/**
 * A container class for many drawable objects.
 * The purpose is grouping of many small objects
 * that represent a larger compound object and
 * applying some operations on all of them as one.
 * @author Roma
 *
 */
public class GLSet implements GLDrawable 
{
	private Vector<GLDrawable> set = new Vector<GLDrawable>();
	
	public GLSet()
	{
		
	}
	
	public GLSet(GLDrawable[] arr)
	{
		if(arr != null)
		{
			for(int i = 0; i < arr.length; i++)
				add(arr[i]);
		}
	}
	
	public void add(GLDrawable obj)
	{
		if(this == obj) return;
		set.add(obj);
	}
	
	public void draw(float[] matrix) 
	{
		for(GLDrawable obj : set)
		{
			obj.draw(matrix);
		}
	}

	@Override
	public GLVec2 getPos() 
	{
		if(set.isEmpty()) return null;
		return set.firstElement().getPos();
	}

	@Override
	public void setPos(GLVec2 pos) 
	{
		if(set.isEmpty()) return;
		GLVec2 anchor = set.firstElement().getPos();
		/* 
		 * We want to keep relative distance between elements in the set.
		 * Not just put them all in one spot 
		 */
		for(GLDrawable obj : set) 
		{
			GLVec2 delta = obj.getPos().sub(anchor);
			obj.setPos(pos.add(delta));
		}
	}

}
